{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "google",
   "metadata": {},
   "source": [
    "##### Copyright 2023 Google LLC."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "apache",
   "metadata": {},
   "source": [
    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "you may not use this file except in compliance with the License.\n",
    "You may obtain a copy of the License at\n",
    "\n",
    "    http://www.apache.org/licenses/LICENSE-2.0\n",
    "\n",
    "Unless required by applicable law or agreed to in writing, software\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "See the License for the specific language governing permissions and\n",
    "limitations under the License.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "basename",
   "metadata": {},
   "source": [
    "# proto_solve"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "link",
   "metadata": {},
   "source": [
    "<table align=\"left\">\n",
    "<td>\n",
    "<a href=\"https://colab.research.google.com/github/google/or-tools/blob/main/examples/notebook/examples/proto_solve.ipynb\"><img src=\"https://raw.githubusercontent.com/google/or-tools/main/tools/colab_32px.png\"/>Run in Google Colab</a>\n",
    "</td>\n",
    "<td>\n",
    "<a href=\"https://github.com/google/or-tools/blob/main/examples/python/proto_solve.py\"><img src=\"https://raw.githubusercontent.com/google/or-tools/main/tools/github_32px.png\"/>View source on GitHub</a>\n",
    "</td>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "doc",
   "metadata": {},
   "source": [
    "First, you must install [ortools](https://pypi.org/project/ortools/) package in this colab."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "install",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install ortools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "code",
   "metadata": {},
   "outputs": [],
   "source": [
    "from ortools.sat.colab import flags\n",
    "from ortools.linear_solver.python import model_builder\n",
    "\n",
    "FLAGS = flags.FLAGS\n",
    "\n",
    "_INPUT = flags.define_string('input', '', 'Input file to load and solve.')\n",
    "_PARAMS = flags.define_string('params', '', 'Solver parameters in string format.')\n",
    "_SOLVER = flags.define_string('solver', 'sat', 'Solver type to solve the model with.')\n",
    "\n",
    "\n",
    "def main(_):\n",
    "    model = model_builder.ModelBuilder()\n",
    "\n",
    "    # Load MPS file.\n",
    "    if not model.import_from_mps_file(_INPUT.value):\n",
    "        print(f'Cannot import MPS file: \\'{_INPUT.value}\\'')\n",
    "        return\n",
    "\n",
    "    # Create solver.\n",
    "    solver = model_builder.ModelSolver(_SOLVER.value)\n",
    "    if not solver:\n",
    "        print(f'Cannot create solver with name \\'{_SOLVER.value}\\'')\n",
    "        return\n",
    "\n",
    "    # Set parameters.\n",
    "    if _PARAMS.value:\n",
    "        solver.set_solver_specific_parameters(_PARAMS.value)\n",
    "\n",
    "    # Enable the output of the solver.\n",
    "    solver.enable_output(True)\n",
    "\n",
    "    # And solve.\n",
    "    solver.solve(model)\n",
    "\n",
    "\n",
    "main()\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
